// src/api/types/user-types.ts

/** 用户角色信息 */
export interface UserRole {
  reId: number;
  reName: string;
}

/** 用户信息 */
export interface UserItem {
  urId: number;
  urName: string;
  urUsername: string;
  urPassword: string;
  urEmail: string;
  createTime: string;
  urAvatar: string;
  urStuats: number; // 0: 禁用, 1: 启用
  urReId: number;
  urSex: number; // 0: 男, 1: 女
  role: UserRole;
}

/** 分页数据结构 */
export interface PageData<T> {
  totalCount: number;
  pageSize: number;
  totalPage: number;
  currPage: number;
  list: T[];
}

/** 用户列表响应结构 */
export interface UserListResponse {
  success: boolean;
  code: number;
  message: string;
  data: {
    page: PageData<UserItem>;
  };
}

/** 查询参数 */
export interface UserQueryParams {
  pageNum?: number;
  pageSize?: number;
  [key: string]: any; // 可扩展其他查询条件
}



// src/api/user-api.ts

import { baseRequestClient, requestClient } from '#/api/request';

/**
 * 获取用户列表
 * @param params 查询参数（pageNum, pageSize 等）
 */
export async function getUserListApi(params: UserQueryParams) {
  const res = await requestClient.get<UserListResponse>('/user/list', {
    params,
  });
  return res;
}

/**
 * 删除用户
 * @param urIds 用户ID数组
 */
export async function deleteUserApi(urIds: String[]) {
  const res = await requestClient.post('/user/delete', urIds);
  return res;
}

/**
 * 导出用户数据
 * @param urIds 用户ID数组
 */
export async function exportUserApi(urIds: number[]) {
  const res = await requestClient.post('/user/export', urIds, {
    responseType: 'blob',
  });
  return res;
}

/**
 * 修改密码
 * @param oldpassword 旧密码
 * @param newpassword 新密码
 */
export async function updatePasswordApi(oldpassword: string, newpassword: string) {
  const res = await requestClient.get('/user/updatePssword', {
    params: { oldpassword, newpassword },
  });
  return res;
}

/**
 * 获取用户详情
 * @param urId 用户ID
 */
export async function getUserInfoApi(urId: number) {
  const res = await requestClient.get(`/user/admin/info/${urId}`);
  return res;
}

/**
 * 添加用户
 * @param user 用户数据
 */
export async function addUserApi(user: Partial<UserItem>) {
  const res = await requestClient.post('/user/save', user);
  return res;
}

/**
 * 更新用户
 * @param user 用户数据
 */
export async function updateUserApi(user: Partial<UserItem>) {
  const res = await requestClient.post('/user/update', user);
  return res;
}


/**
 * 密码重置
 */
export async function resetYourPasswordApi(userId: Number) {
  const res = await requestClient.get('/user/resetYourPassword/'+userId);
  return res;
}
